<!-- 广告列表 -->
<table id="advertList" class="easyui-datagrid" title="{$currentpos}" data-options="
	fit:true,rownumbers:true,animate:true,fitColumns:true,
	url:'{:U('Advert/index')}',idField:'id',border:false,
	toolbar:advertToolbar,pagination:true,singleSelect:true,nowrap:false">
	<thead>
	<tr>
		<th data-options="field:'remark',width:100,align:'center'">说明</th>
		<th data-options="field:'imghref',width:100">图片链接</th>
		<th data-options="field:'imgurl',width:80,align:'center',formatter:buildFace">图片链接</th>
		<th data-options="field:'createtime',width:100,align:'center'">添加时间</th>
		<th data-options="field:'updatetime',width:100,align:'center'">修改时间</th>
		<th data-options="field:'id',width:100,align:'center',formatter:advertOperateText">操作</th>
	</tr>
	</thead>
</table>

<!-- 添加 -->
<div id="advertAddBox" class="easyui-dialog" title="添加广告"
	 data-options="modal:true,closed:true,iconCls:'icon-add',buttons:[{text:'确定',iconCls:'icon-ok',handler:function(){$('#advertAddForm').submit();}},{text:'取消',iconCls:'icon-cancel',handler:function(){$('#advertAddBox').dialog('close');}}]"
	 style="width: 730px; height: 380px;"></div>
<!-- 编辑 -->
<div id="advertEditBox" class="easyui-dialog" title="编辑advert"
	 data-options="modal:true,closed:true,iconCls:'icon-add',buttons:[{text:'确定',iconCls:'icon-ok',handler:function(){$('#advertEditForm').submit();}},{text:'取消',iconCls:'icon-cancel',handler:function(){$('#advertEditBox').dialog('close');}}]"
	 style="width: 730px; height: 380px;"></div>
<script type="text/javascript">
	//工具栏
	var advertToolbar = [
		{ text: '刷新', iconCls: 'icon-reload', handler: advertRefreshList },
		{ text: '添加', iconCls: 'icon-add', handler: advertAdd },
	];
	function buildFace(val,row,index){
		if(!val){
			return '<div style="height:60px;padding:3px;margin:auto;"></div>';
		}else{
			return '<div style="padding:3px;"><img src="'+val+'" height="60" style="padding:1px;border:1px solid #ccc;"></div>';
		}
	}
	//操作格式化
	function advertOperateText(val, row, index){
		var btn = [];
		btn.push('<a href="javascript:void(0);" onclick="advertEdit('+val+')">编辑</a>');
		btn.push('<a href="javascript:void(0);" onclick="advertDelete('+val+')">删除</a>');
		return btn.join(' | ');
	}
	//刷新
	function advertRefreshList(){
		$('#advertList').datagrid('reload');
	}
	//添加
	function advertAdd(){
		var url = '{:U('Advert/advertAdd')}';
		$('#advertAddBox').dialog({href:url});
		$('#advertAddBox').dialog('open');
	}
	//advert编辑
	function advertEdit(id){
		if(typeof(id) !== 'number'){
			$.messager.alert('提示信息', '请选择一条记录', 'error');
			return false;
		}
		var url = '{:U('Advert/advertEdit')}';
		url += url.indexOf('?') != -1 ? '&id='+id : '?id='+id;
		$('#advertEditBox').dialog({href:url});
		$('#advertEditBox').dialog('open');
	}
	//advert删除
	function advertDelete(id){
		if(typeof(id) !== 'number'){
			$.messager.alert('提示信息', '未选择', 'error');
			return false;
		}
		$.messager.confirm('提示信息', '确定要删除吗？', function(result){
			if(!result) return false;
			$.post('{:U('Advert/advertDelete')}', {id: id}, function(data){
				if(!data.status){
					$.messager.alert('提示信息', data.info, 'error');
				}else{
					advertRefreshList();
					$.messager.alert('提示信息', data.info, 'info');
				}
			}, 'json');
		});
	}
</script>